﻿using System;
using System.Collections.Generic;
using System.Text;
using Nissen_Common;
using Nissen_Dao;
using Nissen_Model;

namespace Nissen_Marking.Forms
{
	public class UserLoginLogService
	{
		public void SaveLogoffLog()
		{
			var currentUser = ContextManager.Instance.CurrentUser;

			LoginLog loginLog = new LoginLog();

			loginLog.LoginDate = DateTime.Now;
			loginLog.LoginType = false;
			loginLog.MachineCode = currentUser.Machine == null ? System.Net.Dns.GetHostName() : currentUser.Machine.MachineName;
			loginLog.NissenSSO = currentUser.NissenSSO.NissenSSOCode;
			loginLog.WorkerNo = currentUser.LoginSSO;
			LoginLogDao loginLogDao = new LoginLogDao();

			loginLogDao.SaveOrUpdateLoginLog(loginLog);
		}

		public void SaveLoginLog()
		{
			var currentUser = ContextManager.Instance.CurrentUser;

			LoginLog loginLog = new LoginLog();

			loginLog.LoginDate = DateTime.Now;
			loginLog.LoginType = true;
			loginLog.MachineCode = currentUser.Machine == null ? System.Net.Dns.GetHostName() : currentUser.Machine.MachineName;
			loginLog.NissenSSO = currentUser.NissenSSO.NissenSSOCode;
			loginLog.WorkerNo = currentUser.LoginSSO;
			LoginLogDao loginLogDao = new LoginLogDao();

			loginLogDao.SaveOrUpdateLoginLog(loginLog);
		}
	}
}
